#==================================================================
# Reference:
#	https://shields.io/
#	https://makefiletutorial.com/
#==================================================================

all: help


CURRENT_DIR := $(shell basename "$(CURDIR)")
OUTPUT_DIR := ${HOME}/tmp/cmake_builds/${CURRENT_DIR}
PROJECT_NAME := "helloworld_app"

## build@构建项目
.PHONY:build
build:
	@echo "\033[33m⚙️  正在构建...\033[0m"
	@cmake -B ${OUTPUT_DIR} && cd ${OUTPUT_DIR} && make -j8
	@echo "\033[0;31m🍩 构建成功\033[0m"
	@echo "${OUTPUT_DIR}/"
	@ls -lh --color=auto ${OUTPUT_DIR}


## run@运行程序
.PHONY:run
run: 
	@cd ${OUTPUT_DIR} && ./${PROJECT_NAME}


## test@测试项目
.PHONY:test
test:
	@echo "\033[33m🧪  正在测试...\033[0m"
	@cd ${OUTPUT_DIR} && make test


## clean@清理文件
.PHONY:clean
clean:
	@echo "\033[33m✈️  正在清理...\033[0m"
	rm -rf ${OUTPUT_DIR}
	rm -rf ./bin
	rm -rf ./build
	rm -rf ./logs
	rm -rf ./log
	rm -rf ./cache
	rm -rf ./pid
	rm -rf ./release
	rm -rf ./debug
	rm -rf ./deploy
	rm -rf ./tmp
	rm -rf ./temp
	rm -rf cmake_build
	rm -rf cmake-build*
	rm -rf ./vendor/*
	rm -rf .DS_Store
	@echo "\033[31m✅ 清理完毕\033[0m\n"


## help@查看帮助
.PHONY:help
help:Makefile
	@echo "Usage:\n  make [command]"
	@echo
	@echo "Available Commands:"
	@sed -n "s/^##//p" $< | column -t -s '@' |grep --color=auto "^[[:space:]][a-zA-Z0-9_]\+[[:space:]]"
	@echo
	@echo "更多内容,请参考： https://github.com/hollson\n"
